package cn.numeron.wandroid

import android.app.Application
import cn.numeron.discovery.Discoveries
import coil.ImageLoader
import coil.ImageLoaderFactory
import cn.numeron.common.frame.IInitializer
import dagger.hilt.android.HiltAndroidApp
import okhttp3.OkHttpClient
import javax.inject.Inject

@HiltAndroidApp
class WandroidApplication : Application(), ImageLoaderFactory {

    @Inject
    lateinit var okHttpClient: OkHttpClient

    override fun onCreate() {
        super.onCreate()
        Discoveries.getAllInstances<IInitializer>().forEach {
            it.onInit(this)
        }
    }

    /** Coil推荐创建方式，调用扩展方法时自动调用此方法，并且保持全局单例 */
    override fun newImageLoader(): ImageLoader {
        return ImageLoader.Builder(this)
            .okHttpClient(okHttpClient)
            .build()
    }

}